package com.yssw.client.service.impl;

import java.util.List;

import com.yssw.common.core.domain.entity.SysUser;
import com.yssw.common.utils.DateUtils;
import com.yssw.common.utils.SecurityUtils;
import com.yssw.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yssw.client.service.iClientUserService;

/**
 * 用户信息Service业务层处理
 *
 * @author yssw
 * @date 2023-03-29
 */
@Service
public class ClientUserServiceImpl implements iClientUserService {
    @Autowired
    private SysUserMapper sysUserMapper;


    /**
     * 查询用户信息
     *
     * @param userId 用户信息主键
     * @return 用户信息
     */
    @Override
    public SysUser selectClientUserByUserId(Long userId) {
        return sysUserMapper.selectUserById(userId);
    }

    /**
     * 查询用户信息列表
     *
     * @param sysUser 用户信息
     * @return 用户信息
     */
    @Override
    public List<SysUser> selectClientUserList(SysUser sysUser) {
        sysUser.setUserType(1);
        return sysUserMapper.selectUserList(sysUser);
    }

    /**
     * 新增用户信息
     *
     * @param sysUser 用户信息
     * @return 结果
     */
    @Override
    public int insertClientUser(SysUser sysUser) {
        sysUser.setUserType(1);
        sysUser.setCreateBy(SecurityUtils.getUsername());
        sysUser.setCreateTime(DateUtils.getNowDate());
        sysUser.setPassword(SecurityUtils.encryptPassword(sysUser.getPassword()));
        return sysUserMapper.insertUser(sysUser);
    }

    /**
     * 修改用户信息
     *
     * @param client_User 用户信息
     * @return 结果
     */
    @Override
    public int updateClientUser(SysUser client_User) {
        client_User.setUpdateTime(DateUtils.getNowDate());
        client_User.setUpdateBy(SecurityUtils.getUsername());
        client_User.setPassword(SecurityUtils.encryptPassword(client_User.getPassword()));
        return sysUserMapper.updateUser(client_User);
    }

    /**
     * 批量删除用户信息
     *
     * @param userIds 需要删除的用户信息主键
     * @return 结果
     */
    @Override
    public int deleteClientUserByUserIds(Long[] userIds) {
        return sysUserMapper.deleteUserByIds(userIds);
    }

    /**
     * 删除用户信息信息
     *
     * @param userId 用户信息主键
     * @return 结果
     */
    @Override
    public int deleteClientUserByUserId(Long userId) {
        return sysUserMapper.deleteUserById(userId);
    }

    /**
     * 充值功能
     * @param amount 金额
     *  @param userId 用户信息主键
     * @return
     */
    @Override
    public int payment(String amount,Long userId) {
//        SysUser sysUser = sysUserMapper.selectUserById(userId);
//        if (ObjectUtils.isNotEmpty(sysUser)) {
//            BigDecimal amountDecimal=new BigDecimal(amount);
//            BigDecimal balanceDecimal=new BigDecimal(String.valueOf(sysUser.getBalance()));
//
//        }
        return 0;
    }
}
